<template>
	<view class="global">
		<uni-nav-bar dark :fixed="true" shadow background-color="#007AFF" status-bar title="地址管理" @clickLeft="back"
			leftText="返回" title-align="left" />
		<view class="addressglobal">
				<uni-forms :modelValue="form" ref="formRef"  label-width="180rpx" label-align="right">
							<uni-forms-item name="address" label="地址信息" required>
								<uni-easyinput type="textarea" v-model="form.address" placeholder="请输入地址" />
							</uni-forms-item>
							<uni-forms-item name="user" label="联系人" required>
								<uni-easyinput type="text" v-model="form.user" placeholder="请输入联系人" />
							</uni-forms-item>
							<uni-forms-item name="phone" label="联系方式" required>
								<uni-easyinput type="text" v-model="form.phone" placeholder="请输入联系方式" />
							</uni-forms-item>
							<uni-forms-item>
								<button type="primary" size="mini" @click="saveAddress">确定</button>
							</uni-forms-item>
						</uni-forms>
			</view>
	</view>
</template>

<script>
	import $H from '../../utils/request.js';
	export default {
		data() {
			return {
				form:{},
			}
		},
		onLoad(e) {
			
			if(e.item){
			this.form=JSON.parse(e.item)
				
			}
			this.user = uni.getStorageSync("userinfo");
			this.form.userId=this.user.id
		},
		methods: {
			back(){
				uni.navigateBack()
			},
			saveAddress(){
				if(!this.form.id){
				$H.post("address/add",this.form).then(res=>{
					uni.navigateBack()
				})					
				}else{
					$H.post("address/update",this.form).then(res=>{
					uni.navigateBack()
				})			
					
				}

			}
		}
	}
</script>

<style>
.addressglobal{
	width: 100%;
	box-sizing: border-box;
	background: #fff;
	padding: 10px;
}
.global{
	width: 100%;
	height: 100%;
	background: #e5e5e5;
}
</style>
